package com.epalmpay.controller.channel.bonus;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.bonus.BonusShopSettleLogInDTO;
import com.epalmpay.dto.bonus.BonusShopSettleLogListOutDTO;
import com.epalmpay.dto.bonus.BonusShopSettleLogOutDTO;
import com.epalmpay.dto.bonus.BonusVerifyLogInDTO;
import com.epalmpay.dto.bonus.BonusVerifyLogListOutDTO;
import com.epalmpay.dto.bonus.BonusVerifyShopInDTO;
import com.epalmpay.dto.bonus.BonusVerifyShopListOutDTO;
import com.epalmpay.dto.bonus.BonusVerifyShopOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.system.ShopInDTO;
import com.epalmpay.dto.system.ShopListOutDTO;
import com.epalmpay.service.bonus.IBonusAdjustBatchService;
import com.epalmpay.service.bonus.IBonusVerifyShopService;
import com.epalmpay.service.management.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.annotation.Resource;

/**
 * zsj
 */
@Controller
@RequestMapping(value="/merchant/bonusVerifyShop")
public class BonusVerifyShopController extends BaseController{

    @Resource
    private IBonusAdjustBatchService bonusAdjustBatchService;
    @Resource
    private IBonusVerifyShopService bonusVerifyShopService;
    @Resource
    private IUserService userService;


    @ResponseBody
    @RequestMapping(value = "/bonusVerifyShopList")
    public BonusVerifyShopListOutDTO bonusVerifyShopList(BonusVerifyShopInDTO bonusVerifyShopInDTO, PageDTO pageDTO)throws Exception{
    	BonusVerifyShopListOutDTO bonusVerifyShopListOutDTO = new BonusVerifyShopListOutDTO();
        try {
        	bonusVerifyShopListOutDTO=bonusVerifyShopService.listBonusVerifyShop(bonusVerifyShopInDTO, pageDTO);
            return bonusVerifyShopListOutDTO;
        } catch (ApplicationException ae) {
        	bonusVerifyShopListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusVerifyShopListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusVerifyShopListOutDTO;
    }
    
    
    /**
     * 可核销门店列表
     * @param shopInDTO
     * @param pageDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/shopList")
    public ShopListOutDTO shopList(BonusVerifyShopInDTO bonusVerifyShopInDTO, PageDTO pageDTO)throws Exception{
    	ShopListOutDTO shopListOutDTO = new ShopListOutDTO();
        try {
        	shopListOutDTO=bonusVerifyShopService.listCanShop(bonusVerifyShopInDTO, pageDTO);
            return shopListOutDTO;
        } catch (ApplicationException ae) {
        	shopListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	shopListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return shopListOutDTO;
    }
    

    /**
     * 批量添加门店
     * @param bonusVerifyShopInDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/addBonusVerifyShop")
    public BonusVerifyShopOutDTO addBonusVerifyShop(BonusVerifyShopInDTO bonusVerifyShopInDTO)throws Exception{
    	BonusVerifyShopOutDTO bonusVerifyShopOutDTO = new BonusVerifyShopOutDTO();
    	
        try {
        	Boolean flag=bonusVerifyShopService.addBonusVerifyShop(bonusVerifyShopInDTO);
        	if(flag){
        		bonusVerifyShopOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
        	}else{
        		bonusVerifyShopOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
        	}
        } catch (ApplicationException ae) {
        	bonusVerifyShopOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusVerifyShopOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
		return bonusVerifyShopOutDTO; 
    }
   
    /**
     * 更改核销门店状态
     * @param bonusVerifyShopInDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/updateBonusStatus")
    public BonusVerifyShopOutDTO updateBonusStatus(BonusVerifyShopInDTO bonusVerifyShopInDTO)throws Exception{
    	BonusVerifyShopOutDTO bonusVerifyShopOutDTO = new BonusVerifyShopOutDTO();
        try {
        	Boolean flag=bonusVerifyShopService.updateBonusStatus(bonusVerifyShopInDTO);
        	if(flag){
        		bonusVerifyShopOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
        	}else{
        		bonusVerifyShopOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
        	}
        } catch (ApplicationException ae) {
        	bonusVerifyShopOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusVerifyShopOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
		return bonusVerifyShopOutDTO; 
    }
    
    
    /**
     * 积分结算
     * @param bonusVerifyShopInDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/updateBonusSettlement")
    public BonusVerifyShopOutDTO updateBonusSettlement(BonusShopSettleLogInDTO bonusShopSettleLogInDTO)throws Exception{
    	BonusVerifyShopOutDTO bonusShopSettleLogOutDTO = new BonusVerifyShopOutDTO();
        try {
        	Boolean flag=bonusVerifyShopService.updateBonusSettlement(bonusShopSettleLogInDTO);
        	if(flag){
        		bonusShopSettleLogOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
        	}else{
        		bonusShopSettleLogOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
        	}
        } catch (ApplicationException ae) {
        	bonusShopSettleLogOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusShopSettleLogOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
		return bonusShopSettleLogOutDTO; 
    }
    
    /**
     * 积分核销门店详情
     * @param bonusVerifyShopInDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/bonusVerifyShopView")
    public BonusVerifyShopOutDTO bonusVerifyShopView(BonusVerifyShopInDTO bonusVerifyShopInDTO)throws Exception{
    	BonusVerifyShopOutDTO bonusShopSettleLogOutDTO = new BonusVerifyShopOutDTO();
        try {
        	BonusVerifyShopOutDTO BonusVerifyShopOutDTO=bonusVerifyShopService.BonusVerifyShopView(bonusVerifyShopInDTO);
        	return BonusVerifyShopOutDTO; 
        } catch (ApplicationException ae) {
        	bonusShopSettleLogOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusShopSettleLogOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
		return bonusShopSettleLogOutDTO; 
    }
    
    
    /**
     * 根据门店查询积分月报表  
     * @param shopInDTO
     * @param pageDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/listMonthBonusVerifyLog")
    public BonusVerifyLogListOutDTO listMonthBonusVerifyLog(BonusVerifyLogInDTO bonusVerifyShopInDTO, PageDTO pageDTO)throws Exception{
    	BonusVerifyLogListOutDTO bonusVerifyLogListOutDTO = new BonusVerifyLogListOutDTO();
        try {
        	bonusVerifyLogListOutDTO=bonusVerifyShopService.listMonthBonusVerifyLog(bonusVerifyShopInDTO, pageDTO);
            return bonusVerifyLogListOutDTO;
        } catch (ApplicationException ae) {
        	bonusVerifyLogListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusVerifyLogListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusVerifyLogListOutDTO;
    }
    
    
    /**
     * 根据门店以及月份查询门店核销信息
     * @param shopInDTO
     * @param pageDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/listBonusVerifyLog")
    public BonusVerifyLogListOutDTO listBonusVerifyLog(BonusVerifyLogInDTO bonusVerifyShopInDTO, PageDTO pageDTO)throws Exception{
    	BonusVerifyLogListOutDTO bonusVerifyLogListOutDTO = new BonusVerifyLogListOutDTO();
        try {
        	bonusVerifyLogListOutDTO=bonusVerifyShopService.listBonusVerifyLog(bonusVerifyShopInDTO, pageDTO);
            return bonusVerifyLogListOutDTO;
        } catch (ApplicationException ae) {
        	bonusVerifyLogListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusVerifyLogListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusVerifyLogListOutDTO;
    }
    
    
    /**
     * 积分核销门店详情
     * @param bonusVerifyShopInDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/bonusMonthVerifyShopView")
    public BonusVerifyShopOutDTO bonusMonthVerifyShopView(BonusVerifyShopInDTO bonusVerifyShopInDTO)throws Exception{
    	BonusVerifyShopOutDTO bonusShopSettleLogOutDTO = new BonusVerifyShopOutDTO();
        try {
        	BonusVerifyShopOutDTO BonusVerifyShopOutDTO=bonusVerifyShopService.bonusMonthVerifyShopView(bonusVerifyShopInDTO);
        	return BonusVerifyShopOutDTO; 
        } catch (ApplicationException ae) {
        	bonusShopSettleLogOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusShopSettleLogOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
		return bonusShopSettleLogOutDTO; 
    }
    
    /**
     * 积分结算记录列表  
     * @param shopInDTO
     * @param pageDTO
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/listBonusShopSettleLog")
    public BonusShopSettleLogListOutDTO listBonusShopSettleLog(BonusShopSettleLogInDTO bonusShopSettleLogInDTO, PageDTO pageDTO)throws Exception{
    	BonusShopSettleLogListOutDTO bonusShopSettleLogListOutDTO = new BonusShopSettleLogListOutDTO();
        try {
        	bonusShopSettleLogListOutDTO=bonusVerifyShopService.listBonusShopSettleLog(bonusShopSettleLogInDTO, pageDTO);
            return bonusShopSettleLogListOutDTO;
        } catch (ApplicationException ae) {
        	bonusShopSettleLogListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
        	bonusShopSettleLogListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return bonusShopSettleLogListOutDTO;
    }
}
